package com.example.wordapp.mapper;

import com.example.wordapp.pojo.Word;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface WordMapper {

    @Select("select * from words")
    List<Word> getAll();

    //    select id , word,translate,COALESCE(user_1,0) as 'isWrite' from words where user_1 = 0 or user_1 is null  LIMIT 30
    @Select("select id , word,translate,COALESCE(${userFormart},0) as 'isWrite' from words where ${userFormart} = 0 or ${userFormart} is null  LIMIT 30")
    List<Word> getByUser(String userFormart);


    /**
     * 把单词改成已背的接口
     *
     * @param com 哪一个列(也就是字段)
     * @param id  单词的 id
     * @return 被修改的行
     */
    @Update("update words set ${com} = #{stat} where id = #{id}")
    int updateWriteWord(String com, String id, Integer stat);


    /**
     *
     * @param com   列名
     * @param isWrite   查询是否已背的  1 表示查已背  0 表示查没有背的
     * @return  返回单词列表
     */
    @Select("select id,word,translate, ${com} from words where ${com} = #{isWrite}")
    List<Word> findWriteWordByCom(String com, Integer isWrite);

    /**
     *  将所有的已背单词清空
     * @param com   列(字段)
     * @return      背修改的行
     */
    @Update("update words set ${com} = 0")
    int cleanWriterWords(String com);


}
